﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToPLMX.SimulationStateExporter.CApExportToPlmxStateModificationExporter
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using EngineeringInternalExtension.ObjectsStateExportService;
using System.Collections.Generic;
using System.Drawing;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ExportToPLMX.SimulationStateExporter;

internal class CApExportToPlmxStateModificationExporter : ITxStateModificationExporterEx
{
  private Dictionary<ITxObject, int> m_objectToIndexMap;

  internal CApExportToPlmxObjectsFrameData ObjectsFrameData { get; private set; }

  public CApExportToPlmxStateModificationExporter(
    double time,
    Dictionary<ITxObject, int> objectToIndexMap)
  {
    this.ObjectsFrameData = new CApExportToPlmxObjectsFrameData();
    this.ObjectsFrameData.time = time;
    this.m_objectToIndexMap = objectToIndexMap;
  }

  public CApExportToPlmxStateModificationExporter(CApExportToPlmxObjectsFrameData frameData)
  {
    this.ObjectsFrameData = frameData;
  }

  public void Start()
  {
  }

  public void ExportCamera()
  {
    TxGraphicViewer graphicViewer = TxApplication.ViewersManager.GraphicViewer;
    TxCamera currentCamera = graphicViewer.CurrentCamera;
    RectangleF viewRectangle = graphicViewer.ViewPointData.ViewRectangle;
    TxVector position = currentCamera.Position;
    TxVector referencePoint = currentCamera.ReferencePoint;
    TxVector upVector = currentCamera.UpVector;
    this.ObjectsFrameData.camera = new CApExportToPlmxCameraStateData()
    {
      cpx = position.X,
      cpy = position.Y,
      cpz = position.Z,
      crx = referencePoint.X,
      cry = referencePoint.Y,
      crz = referencePoint.Z,
      cux = upVector.X,
      cuy = upVector.Y,
      cuz = upVector.Z,
      cpa = TxGraphicViewerEx.The.ProjectionType == null ? 1.0 : 0.0,
      cvpz = (double) viewRectangle.Width
    };
  }

  public void ExportCableSettings()
  {
  }

  public ITxStateModificationObjectExporterEx GetObjExporter(ITxObject obj)
  {
    int index = 0;
    CApExportToPlmxStateModificationObjectExporter objExporter = (CApExportToPlmxStateModificationObjectExporter) null;
    if (this.m_objectToIndexMap.TryGetValue(obj, out index))
    {
      objExporter = new CApExportToPlmxStateModificationObjectExporter(obj, index);
      this.ObjectsFrameData.objStates.Add(objExporter.ObjectStateData);
    }
    return (ITxStateModificationObjectExporterEx) objExporter;
  }

  public void End() => this.ObjectsFrameData.SortObjectStates();

  public void ExportRemovedObjects(List<string> removedObjects)
  {
  }
}
